<template>
  <div class="CkmBuy_box" v-loading="loading">
    <div class="CkmBuy_box_text1">
      {{ $t("button.Transfer") }}
    </div>
    <div class="CkmBuy_box_text2"></div>
    <div class="CkmBuy_box_text3">
      {{ $t("button.available8") }}
      <span style="color: #00b0f0">{{ money }}</span
      >{{ $t("button.TransferNumbers") }}
    </div>
    <div class="CkmBuy_box_text4">
      {{ $t("button.From") }}
      <div class="CkmBuy_box_text4_child">{{ uid }}</div>
      <div class="CkmBuy_box_text4_child1">——></div>
      {{ $t("button.TO") }}
      <el-input
        v-model="query.user_code"
        class="CkmBuy_box_text4_child"
      ></el-input>
      <!-- <div  style="border: 1px solid #999999">   
      </div> -->
    </div>
    <div class="CkmBuy_box_text3">
      {{ $t("button.Amount9") }}
      <el-input
        style="width: 312px; height: 53px"
        v-model="query.money"
        :placeholder="$t('button.EnterAmount9')"
      ></el-input>
      {{ $t("button.Point9") }}
      <div class="CkmBuy_box_text7 cursor" @click="ConfirmFn">
        {{ $t("button.Confirm") }}
      </div>
    </div>

    <div class="CkmBuy_box_text6">
      <span v-if="moneyChange">{{ query.user_code }}</span>
      <span
        style="color: #666666; display: inline-block; margin: 0 10px"
        v-if="moneyChange"
        >{{ query.money }}</span
      >{{ $t("button.TransferNumbers") }}
    </div>
    <div class="CkmBuy_box_text8">
      <div class="CkmBuy_box_text8_text cursor" @click="btnFn">
        {{ $t("button.Send") }}
      </div>
      <span style="color: #00b0f0; font-size: 24px">{{
        $t("button.Send1")
      }}</span>
    </div>
    <div class="MyPonit_box_child9">{{ $t("button.Transfer8") }}</div>
    <div class="table_text">
      <el-table :data="tableDataCurrent" border style="width: 100%">
        <el-table-column prop="date" :label="$t('button.time9')">
        </el-table-column>
        <el-table-column prop="p_code" :label="$t('button.TO1')">
        </el-table-column>
        <el-table-column prop="money" :label="$t('button.Amount10')">
        </el-table-column>
        <el-table-column prop="status" :label="$t('button.Action10')">
          <span style="color: #ccc">{{ "complete" }}</span>
        </el-table-column>
      </el-table>
      <el-pagination
        style="text-align: center; margin: 20px 0"
        background
        v-show="tableData.total > 0"
        :total="tableData.total"
        :page.sync="listQuery.page"
        :page-size="listQuery.limit"
        :size.sync="listQuery.limit"
        @current-change="getLists"
        layout="total,prev, pager, next"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import {
  transfer,
  transferorder,
  transfer_port,
  indexs,
} from "@/api/product.js"; //  积分赠送 积分赠送记录

export default {
  name: "CKmbuy",
  data() {
    return {
      moneyChange: false, // 用来判断是否点击提交订单按钮
      listQuery: {
        // Dang当前页
        page: 1,
        // 每页多少条
        limit: 3,
      },
      loading: false, // loading
      tableData: {},
      tableDataCurrent: [], // 列表详情
      query: {
        user_id: "", // 账户id
        user_code: "", // 赠送人账户
        money: "", // 赠送金额
      },
      userQuery: {
        user_id: "",
        page: 1,
      },
      uid: "",
      money: "", // 被赠送者积分
      user_code: {
        user_code: "", // userid
      },
    };
  },
  created() {
    this.query.user_id = sessionStorage.getItem("id");
    this.userQuery.user_id = sessionStorage.getItem("id");
    this.user_code.user_code = sessionStorage.getItem("user_code");
    this.uid = sessionStorage.getItem("id");
    this.transferorder(this.userQuery);
    this.indexs(this.userQuery);
  },
  methods: {
    // 个人信息
    async indexs(query) {
      try {
        const data = await indexs(query);
        console.log(data);
        this.money = data.data.withdraw_money; // grade
        this.buyQuery.email = data.data.email;
      } catch (error) {
        console.log(error);
      }
    },
    ConfirmFn() {
      this.moneyChange = true;
    },
    // 记录状态
    formatterposttype(row) {
      return row.status == 0 ? "未审核" : row.status == 1 ? "审核通过" : "拒绝";
    },
    // 分页
    getLists(val) {
      console.log(val);
      this.loadings = true;
      this.tableDataCurrent = this.tableData.data.slice(
        (val - 1) * this.listQuery.limit,
        val * this.listQuery.limit
      );
      console.log((this.listQuery.page - 1) * this.listQuery.limit);
      console.log(this.listQuery.page * this.listQuery.limit);
      this.loadings = false;
      console.log(this.tableDataCurrent);
    },
    // 赠送记录
    async transferorder(query) {
      try {
        const data = await transferorder(query);
        this.tableData = data.data;
        this.getLists(1);
        console.log(data);
      } catch (error) {
        console.log(error);
      }
    },
    // 发送按钮
    btnFn() {
      this.transfer(this.query);
    },
    // 赠送者金额
    async transfer_port(query) {
      try {
        const data = await transfer_port(query);
        console.log(data);
      } catch (error) {
        console.log(error);
      }
    },
    // 赠送接口
    async transfer(query) {
      this.loading = true;
      try {
        const data = await transfer(query);
        if (data.result_code == 200) {
          this.indexs(this.userQuery);
          this.$message({
            type: "success",
            message: data.msg,
          });
          this.this.transferorder(this.userQuery);
          this.transfer_port(this.user_code);
        } else {
          this.$message({
            type: "error",
            message: data.msg,
          });
        }
        this.loading = false;
        console.log(data);
      } catch (error) {
        this.loading = false;
        console.log(error);
      }
    },
  },
};
</script>

<style scoped>
.el-table {
  font-size: 20px;
}
::v-deep .el-table .el-table__cell {
  padding: 20px 0 !important;
}
.table_text {
  margin: 75px 142px 0;
}
::v-deep .el-pagination span:not([class*="suffix"]) {
  font-size: 22px;
  line-height: 44px;
}
::v-deep .btn-prev {
  text-align: center;
  line-height: 33px;
  width: 44px !important;
  height: 44px !important;
}
::v-deep .btn-next {
  text-align: center;
  line-height: 33px;
  width: 44px !important;
  height: 44px !important;
}
::v-deep .el-pager li {
  font-size: 20px;
  text-align: center;
  line-height: 44px;
  width: 44px !important;
  height: 44px !important;
}
::v-deep .el-input {
  margin-left: 30px;
  width: 100px;
  height: 40px;
  background: #f4f3f3;
  border: 2px solid #999999;
  border-radius: 6px;
}
::v-deep .el-input__inner {
  width: 100%;
  height: 100%;
  font-size: 20px;
}
::v-deep .el-radio__inner {
  width: 20px !important;
  height: 20px !important;
}
::v-deep .el-radio__label {
  font-size: 20px !important;
}
.CkmBuy_box {
  box-sizing: border-box;
  width: 100%;
  height: 922px;
  background: #ffffff;
}
.CkmBuy_box_text1 {
  margin: 62px 0 0 132px;
  height: 42px;
  font-size: 56px;
  font-family: Arial;
  font-weight: bold;
  color: #1a1a1a;
}
.CkmBuy_box_text2 {
  margin: 53px 0 0 0;
  width: 1918px;
  height: 2px;
  background: #bfbfbf;
}
.CkmBuy_box_text3 {
  margin: 26px 0 0 132px;
  height: 23px;
  font-size: 30px;
  font-family: Arial;
  font-weight: 400;
  color: #666666;
}
.CkmBuy_box_text4 {
  margin: 60px 0 0 132px;
  box-sizing: border-box;
  font-size: 24px;
  font-family: Arial;
  font-weight: 400;
  color: #666666;
  line-height: 18px;
}
.CkmBuy_box_text5 {
  margin: 34px 0 0 132px;
}
.CkmBuy_box_text5_child1 {
  margin-right: 40px;
  display: inline-block;
  width: 174px;
  height: 40px;
  background: #dcdcdc;
  border-radius: 6px;
  font-size: 24px;
  font-family: Arial;
  font-weight: 400;
  text-align: center;
  color: #1a1a1a;
  line-height: 40px;
}
.CkmBuy_box_text5_child2 {
  margin-left: 34px;
  display: inline-block;
  width: 89px;
  height: 23px;
  font-size: 24px;
  font-family: Arial;
  font-weight: 400;
  color: #666666;
  line-height: 110px;
}
.CkmBuy_box_text7 {
  margin-left: 20px;
  display: inline-block;
  width: 160px;
  height: 50px;
  background: #00b0f0;
  border-radius: 10px;
  font-size: 25px;
  font-family: Arial;
  font-weight: 400;
  text-align: center;
  color: #ffffff;
  line-height: 50px;
}
.CkmBuy_box_text6 {
  margin: 60px 0 0 251px;
  height: 23px;
  font-size: 24px;
  font-family: Arial;
  font-weight: 400;
  color: #1a1a1a;
}
.CkmBuy_box_text8 {
  margin: 26px 0 0 132px;
}
.CkmBuy_box_text8_text {
  margin-right: 20px;
  display: inline-block;
  width: 492px;
  height: 63px;
  background: #00b0f0;
  border-radius: 10px;
  font-size: 30px;
  font-family: Arial;
  text-align: center;
  font-weight: 400;
  color: #ffffff;
  line-height: 63px;
}
.MyPonit_box_child9 {
  margin: 0 0 0 152px;
  height: 28px;
  font-size: 30px;
  font-family: Arial;
  font-weight: bold;
  color: #1a1a1a;
  line-height: 110px;
}
.CkmBuy_box_text4_child {
  display: inline-block;
  width: 154px;
  height: 41px;
  background: #f4f3f3;
  border-radius: 10px;
  line-height: 41px;
  text-align: center;
}
.CkmBuy_box_text4_child1 {
  display: inline-block;
  margin: 0 10px;
}
</style>